﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// 自定义UI：buff列表生成器
/// </summary>
public class BuffListGenerator : MonoBehaviour
{
    //最大buff显示数量
    public int maxBuffNums;
    //buff持有组件
    public BuffBox buffBox;
    //buff持有组件列表
    private List<BuffBox> buffBoxes = new List<BuffBox>();

    private void Start()
    {
        buffBoxes.Clear();
        for (int i = 0; i < maxBuffNums; i++)
        {
            var newbuffbox = Instantiate(buffBox, this.transform);
            buffBoxes.Add(newbuffbox);
        }
    }


    //生成或更新buff显示
    public void AddAndUpdateBuffList(BuffableEntity buffableEntity)
    {
        //清理数据
        for (int i = 0; i < buffBoxes.Count; i++)
        {
            buffBoxes[i].CleanData();
        }

        //赋值
        for (int i = 0; i < buffableEntity.buffList.Count; i++)
        {
            buffBoxes[i].buff = buffableEntity.buffList[i];
            buffBoxes[i].RegisterBuffInfo();
        }
    }
}
